<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/2/14
 * Time: 11:49
 */
namespace app\domain;
use app\server\request;
use app\server\UserAuth;
use rap\config\Config;

class user
{

    public function insertUserAuth ($data) {

        $data = [
          'user_id' => $data['user_id'],
          'token' => $data['token'],
          'nickname' => $data['name'],
          'head' => $data['head'],
          'sex' => $data['sex'],
          'phone' => $data['phone'],
          'create_time' => date("Y-m-d H:i:s", time())
        ];

        $res = UserAuth::insertUserAuth($data);

        return $res;
    }

    public function getUserAuthInfo ($where, $field = "*") {

        $data = UserAuth::getUserAuthInfo($where, $field);

        return $data;
    }

    public function updateUserAuth($where, $data){
        $res = UserAuth::updateUserAuth($where, $data);

        return $res;
    }

    public function getUserGold ($where) {

        $param = http_build_query($where);

    }

    public function getUserGoldCount ($user_id) {
        $config = new Config();
        $data = $config->getFileConfig();

        $url = $data['gold_url']['url'];
        $where = [
            'user_id' => $user_id,
            'secret' => $data['app_info']['app_secret']
        ];
        $data = request::getRequestMethod($url, $where);

        return $data['data'];

    }

    public function getUserToken ($userInfo) {

        $userAgent = $userInfo;
        $info = strstr($userAgent, "MAGAPPX");
        $info=explode("|",$info);
        $agent=["version"=>$info[1],//客户端版本信息 4.0.0
            "client"=>$info[2],//客户端信息可以获取区分android或ios 可以获取具体机型
            "site"=>$info[3],  //站点名称  如lxh
            "device"=>$info[4],//设备号    客户端唯一设备号
            "sign"=>$info[5],  //签名     可以验证请求是否伪造 签名算法见下面详细说明
            "signCloud"=>$info[6],//云端签名 这个签名马甲内部使用
            "token"=>$info[7]//用户token 用户的token信息
        ];

        return $agent;
    }
}